"""
这个文件, 是为了测试ihrm项目, 能够顺利删除员工

1. 删除之前, 先添加数据, 确保ID存在
2. 调用删除接口
3. 查询数据库, 校验数据发生了变化
4. 最后, 删除掉添加的ID
"""

import requests

from db_tool import DBTools


class TestIhrmDelete (object):
    def setup(self):
        db=DBTools()
        db.db_uid("INSERT INTO bs_user(id, mobile, username) VALUES('1122334', '13876546783', '惠主播测试员');")
    def teardown(self):
        db=DBTools()
        db.db_uid("DELETE FROM bs_user WHERE id = '1122334';")
    def test_emp_delete_ok(self):
        resp=requests.delete(url="http://ihrm-test.itheima.net/api/sys/user/" + "1122334",
                               headers={"Authorization": "10c75a6e-6b04-4aee-ab72-aa580d0ba364"})
        # print(resp.json())
        #
        assert 200 == resp.status_code
        assert "操作成功" in resp.json().get("message")

     # 二. 查询数据库
        db = DBTools()
        result = db.query_one("SELECT is_delete FROM bs_user WHERE id = '1122334';")
        print("查询数据库", result)
        assert 1 == result[0]  # is_delete == 1 说明进行了逻辑删除
